package ru.compft.common.aop;

/**
 * User: ASUS
 * Date: 02.11.12
 * Time: 10:14
 */
public class ServiceThread extends Thread {
    private int count; // сколько раз работаем 
    private final SomeTestService service;
    private final String name;

    public ServiceThread(SomeTestService service, String name) {
        this.service = service;
        this.name = name;
        this.setName(name);
    }

    @Override
    public void run() {
        while (true) {
            count++;
            final long random = (long) (Math.random() * 5);
            // отдыхаем
            try {
                Thread.sleep(random * 1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }

            service.executeOperation1();


            if (count >= 5) break;
        }

    }
}
